//
//  ReportProjectDetailCell.m
//  efairy
//
//  Created by 李锋 on 2019/3/19.
//  Copyright © 2019年 East. All rights reserved.
//

#import "ReportProjectDetailCell.h"

@implementation ReportProjectDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}

-(void)initView{
    self.contentView.backgroundColor = [UIColor whiteColor];
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, self.contentView.frame.origin.y, SCREEN_WIDTH, 8)];
    line.backgroundColor = ColorFromRGB(0xeff0f4);
    
    _projectTitle = [[UILabel alloc]init];
    _projectTitle.textColor = ColorFromRGB(0x333333);
    _projectTitle.font = [UIFont boldSystemFontOfSize:16.f];
    
    _score = [[UILabel alloc]init];
    _score.textColor = ColorFromRGB(0xFF7200);
    _score.font = [UIFont systemFontOfSize:13.f];
    _score.textAlignment = NSTextAlignmentRight;
    
    UIView *line2 = [[UIView alloc]init];
    line2.backgroundColor = ColorFromRGB(0xe5e5e5);
    
    _projectUserTitle = [[UILabel alloc]init];
    _projectUserTitle.textColor = ColorFromRGB(0x333333);
    _projectUserTitle.font = [UIFont systemFontOfSize:14.f];
    _projectUserTitle.text = @"项目负责人";
    
    _projectUser = [[UILabel alloc]init];
    _projectUser.textColor = ColorFromRGB(0x666666);
    _projectUser.font = [UIFont systemFontOfSize:14.f];
    
    
    _phoneImage = [[UIImageView alloc]init];
    _phoneImage.image = [UIImage imageNamed:@"icon_call_phone"];
    _phoneImage.userInteractionEnabled = YES;
    UITapGestureRecognizer *callphone = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickCallPhone:)];
    [_phoneImage addGestureRecognizer:callphone];
    
    _reportMarkerTitle  = [[UILabel alloc]init];
    _reportMarkerTitle.textColor = ColorFromRGB(0x333333);
    _reportMarkerTitle.font = [UIFont systemFontOfSize:14.f];
    _reportMarkerTitle.text = @"报告总结";
    
    _reportMarker = [[UILabel alloc]init];
    _reportMarker.textColor = ColorFromRGB(0x666666);
    _reportMarker.font = [UIFont systemFontOfSize:14.f];
    _reportMarker.numberOfLines = 0;
    
    UIView *whiteline = [[UIView alloc]init];
    whiteline.backgroundColor = [UIColor whiteColor];
    
    [self.contentView sd_addSubviews:@[line,_projectTitle,_score,line2,_projectUserTitle,_projectUser,_phoneImage,
                                  _reportMarkerTitle,_reportMarker,whiteline]];
    
    _score.sd_layout.heightIs(40).widthIs(60).rightSpaceToView(self.contentView, 12).topSpaceToView(line,0);
    _projectTitle.sd_layout.heightIs(40).topSpaceToView(line, 0).leftSpaceToView(self.contentView, 12).rightSpaceToView(_score, 0);
    line2.sd_layout.widthIs(SCREEN_WIDTH).heightIs(0.5).topSpaceToView(_projectTitle, 0);
    _projectUserTitle.sd_layout.heightIs(38).topSpaceToView(line2, 0).leftSpaceToView(self.contentView, 12).widthIs(84);
    _phoneImage.sd_layout.heightIs(24).widthIs(24).rightSpaceToView(self.contentView, 12).topSpaceToView(line2, 7);
    _projectUser.sd_layout.heightIs(38).leftSpaceToView(_projectUserTitle, 0).rightSpaceToView(_phoneImage, 10).topSpaceToView(line2, 0);
    
    _reportMarkerTitle.sd_layout.heightIs(14).widthIs(84).topSpaceToView(_projectUserTitle, 0).leftSpaceToView(self.contentView, 12);
    _reportMarker.sd_layout.leftSpaceToView(_reportMarkerTitle, 0).rightSpaceToView(self.contentView, 12).topEqualToView(_reportMarkerTitle).autoHeightRatio(0).minHeightIs(14).maxHeightIs(100);
    whiteline.sd_layout.heightIs(12).topSpaceToView(_reportMarker, 0).widthIs(SCREEN_WIDTH);
    [self setupAutoHeightWithBottomView:whiteline bottomMargin:2];
    
}

-(void)setDataModel:(ReportProjectDetailModel *)data{
    if(data){
        _projectTitle.text = data.efairyproject_name;
        _score.text = [NSString stringWithFormat:@"评分%lu",data.efairyproject_security_score];
        _projectUser.text = data.efairyproject_user_name;
        ProjectReportSummary *summary = data.efairyproject_report_summary;
        if(summary){
            if(summary.report_summary_list.count > 0){
                NSString *str = [NSString stringWithFormat:@"1.%@",summary.report_summary_list[0]];
                if(summary.report_summary_list.count > 1){
                    for(int i=1;i<summary.report_summary_list.count; i++){
                        str = [str stringByAppendingFormat:@"%d.%@%@",i+1,@"/n", summary.report_summary_list[i]];
                    }
                }
                _reportMarker.text = str;
            }
        }
       
        
    }
}

-(void)onClickCallPhone:(UITapGestureRecognizer*)tap{
    __weak typeof(self) weakSelf = self;
    if(weakSelf.callPhoneBlock){
        weakSelf.callPhoneBlock();
    }
}

@end
